if ( !FBDEditor ) FBDEditor = {};

FBDEditor.demo = function () {
/*
    demo for FBDEditor 1.0
    Copyright (C) 2008-2009 Yuriy Butenko y.v.butenko@gmail.com

    required yWin;

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
	var items = [
	{"txt":"create variables","rec":[["loadSample",0],
		["button","variable"],["goto",352,208],["click"],["text","def","myVar1"],["OK"],
		["button","constant"],["goto",352,272],["click"],["text","def","\"FBDEditor\""],["OK"],
		["button","output"],["goto",352,368],["click"],["text","def","myOut"],["OK"],
		["button","input"],["goto",352,336],["click"],["text","def","myIn"],["OK"],
		["rClick"],["wait",1500] ]},
	{"txt":"draw traces","":"","rec":[["loadSample",0],["moveWin","status",526,10],["moveWin","function blocks",526,200],
		["tool","FBDEditor_traceB"],
		["goto",168,304],["click"],["goto",456,304],["click"],
		["goto",456,336],["click"],["goto",168,384],["click"],
		["goto",168,224],["click"],["goto",456,272],["click"],["tool","FBDEditor_traceB"],["wait",1500]]},
	{"txt":"delete Entities","rec":[["loadSample",7],["moveWin","status",526,10],["moveWin","function blocks",526,200],
		["tool","FBDEditor_delB"],
		["entity","demoDelEntity001"],["entity","demoDelEntity002"],
		["entity","demoDelEntity003"],["entity","demoDelEntity004"],
		["goto",31,256],["click"],["goto",366,110],["click"],
		["goto",305,144],["click"],["goto",383,383],["click"],["tool","FBDEditor_delB"],["wait",1500]]},
	{"txt":"move Entities","rec":[["loadSample",8],["moveWin","status",526,10],["moveWin","function blocks",526,200],
		["tool","FBDEditor_moveB"],
		["entity","demoMoveEntity001"],["goto",232,520],["click"],
		["entity","demoMoveEntity002"],["goto",232,536],["click"],
		["goto",496,544],["click"],["goto",799,414],["click"],
		["goto",504,416],["click"],["goto",504,464],["click"],
		["tool","FBDEditor_moveB"],["wait",1500]]},
	{"txt":"copy Entities","rec":[["loadSample",9],["moveWin","status",526,10],["moveWin","function blocks",526,200],
		["tool","FBDEditor_copyB"],
		["entity","demoCopyEntity001"],["goto",232,536],["click"],["rClick"],
		["entity","demoCopyEntity002"],["goto",400,536],["click"],["rClick"],
		["goto",336,257],["click"],["goto",31,398],["click"],
		["goto",372,304],["click"],["goto",372,158],["click"],
		["tool","FBDEditor_copyB"],["wait",1500]]},
	{"txt":"change Entities","rec":[["loadSample",5],["moveWin","status",526,10],["moveWin","function blocks",526,200],
		["tool","FBDEditor_editB"],
		["entity","demoEditEntity001"],["text","def","levelDMUX"],["OK"],
//		["goto",32,240],["click"],["goto",176,128],["click"],
//		["text","def","level5"],["OK"],
//		["text","def","level4"],["OK"],
//		["text","def","level3"],["OK"],
//		["text","def","level2"],["OK"],
//		["text","def","level1"],["OK"],
		["goto",188,160],["eClick","demoEditEntity002"],["goto",204,160],["click"],
		["goto",400,216],["eClick","demoEditEntity003"],["goto",320,304],["click"],
		["goto",432,304],["eClick","demoEditEntity003"],["goto",368,392],["click"],
		["goto",344,382],["eClick","demoEditEntity003"],["goto",336,360],["click"],
		["tool","FBDEditor_editB"],["wait",1500]]},
	{"txt":"get 'about'","rec":[["tool","FBDEditor_aboutB"],["OK"],["wait",1500]]},
	{"txt":"get 'help'","rec":[["tool","FBDEditor_helpB"],["wait",1500]]},
	{"txt":"load drawing","rec":[["tool","FBDEditor_loadB"],
		["text","def","c:\\myDrawing"],["CANCEL"],["wait",1500]]},
	{"txt":"save drawing","rec":[["tool","FBDEditor_saveB"],
		["text","def","c:\\myDrawing"],["CANCEL"],["wait",1500]]},
	{"txt":"code generation","rec":[["tool","FBDEditor_generateB"],
		["text","def","c:\\myClass"],["CANCEL"],["wait",1500]]},
	{"txt":"move windows","rec":[
		["CAPTION","function blocks"],["goto",110,460,true],["click",true],
		["CAPTION","status"],["goto",700,150,true],["click",true],["goto",500,300],["wait",1500]]}
	];
	var ctxt = this;
	var isIE = navigator.userAgent.indexOf( "MSIE" ) != -1 && navigator.userAgent.indexOf( "opera" ) == -1;

	var lock = document.createElement( "div" );
	document.body.appendChild( lock );
	lock.className = "FBDEditor_demo_locker";
	lock.style.display = "none";
	if ( isIE ) {
		var f1 = function () {
			lock.style.left = document.body.scrollLeft + "px";
			lock.style.top = document.body.scrollTop + "px";
		};
		var f2 = function () {
			lock.style.width = document.body.clientWidth + "px";
			lock.style.height = document.body.clientHeight + "px";
		};
		window.attachEvent("onscroll",f1);
		window.attachEvent("onresize",f2);
		f1();
		f2();
	};

	var menu = document.createElement( "div" );
	lock.onclick = lock.onmousemove = menu.onclick = menu.onmousemove = function ( e ) {
		if ( e ) e.stopPropagation();
		else window.event.cancelBubble = true;
	};
menu.style.top = "-692px";
	menu.className = "FBDEditor_demo_menu";
	menu.innerHTML = '<a class="FBDEditor_demo_playAll" href="demo">play all</a>'
		+'<div class="FBDEditor_demo_items"></div>'
		+'<a class="FBDEditor_demo_cancell" href="demo">cancell</a>'
		+'<a class="FBDEditor_demo_exit" href="demo">exit</a>';
	var currentTask = null;
	var onclick = function ( e ) {
		stopPropagation( e );
		if ( player.i > 1000 ) newMode.call(this);
		return false;
	};
	var newMode = function () {
		cancelPressed = false;
		if ( currentTask ) currentTask.className = "";
		this.className = "Selected";
		currentTask = this;
		player( items[this._numDemo].rec );
	};
	for ( var i = 0, e; i < items.length; i++ ) {
		menu.childNodes[1].appendChild( e = document.createElement( "a" ) );
		e.appendChild( document.createTextNode( items[i].txt ) );
		e.href = "demo";
		e._numDemo = i;
		e.onclick = onclick;
		if ( i == 0 ) e.style.marginTop = "16px";
		items[i].mItem = e;
	};
	document.body.appendChild( menu );
	var stopPropagation = function ( e ) {
		if ( e ) e.stopPropagation();
		else window.event.cancelBubble = true;
	};
	var endPlayAction = null;
	var currentItem = 0;
	menu.childNodes[0].onclick = function ( e ) {
		currentItem = 0;
		endPlayAction = function () {
			if ( currentItem < items.length ) {
				newMode.call(items[currentItem].mItem);
				currentItem++;
			} else {
				endPlayAction = null;
			};
		};
		if ( player.i < 1000 ) return false;
		endPlayAction();
		return false;
	};
	var cancelPressed = false;
	menu.childNodes[2].onclick = function ( e ) {
		endPlayAction = null;
		cancelPressed = true;
		return false;
	};
	menu.childNodes[3].onclick = function ( e ) {
		cancelPressed = true;
		endPlayAction = off;
		if ( player.i < 1000 ) return false;
		off();
		return false;
	};
	var mv = function () {
		if ( mv.delta > 0 ? menu.offsetTop < mv.endPoint : menu.offsetTop > mv.endPoint )
			menu.style.top = menu.offsetTop + mv.delta + "px";
		else clearInterval( mv.interval );
	};
	mv.interval = null;
	mv.endPoint = null;
	mv.delta = null;
	var on = this.on = function () {
		mv.endPoint = 8;
		mv.delta = +20;
		mv.interval = setInterval(mv,10);
		lock.style.display = "";
		moveCursorTo.on();
	};
	var off = this.off = function () {
		mv.endPoint = -700;
		mv.delta = -20;
		mv.interval = setInterval(mv,10);
		lock.style.display = "none";
		moveCursorTo.off();
		ctxt.controller._loadSample( samples[0] );
	};
	var moveCursorTo = function ( x, y, obj, cb, where ) {
		moveCursorTo.ent.style.display = "";
		var x0 = moveCursorTo.x0;
		var y0 = moveCursorTo.y0;
		var dist = Math.sqrt( ( x0 - x ) * ( x0 - x ) + ( y0 - y ) * ( y0 - y ) );
		moveCursorTo.i = Math.max( Math.round( dist / 5 ), 1 );
		moveCursorTo.delta = Math.PI / 2 / moveCursorTo.i;
		moveCursorTo.deltaX = x - x0;
		moveCursorTo.deltaY = y - y0;
		moveCursorTo.xN = x;
		moveCursorTo.yN = y;
		moveCursorTo.cb = cb;
		moveCursorTo.obj = obj;
		moveCursorTo.where = where || document;
		moveCursorTo.h = setInterval( moveCursorTo.action, 40 );
	};
	moveCursorTo.action = function () {
		var dist = Math.sin( moveCursorTo.i * moveCursorTo.delta );
		moveCursorTo.ent.style.left =
			( moveCursorTo.x0 = Math.round( moveCursorTo.xN - moveCursorTo.deltaX * dist ) ) - 32 + "px";
		moveCursorTo.ent.style.top =
			( moveCursorTo.y0 = Math.round( moveCursorTo.yN - moveCursorTo.deltaY * dist ) ) - 32 + "px";
		moveCursorTo.where.onmousemove( {"pageX":moveCursorTo.x0, "pageY":moveCursorTo.y0, "ctrlKey":false, "stopPropagation":function(){} } );
		if ( moveCursorTo.i-- == 0 ) {
			clearInterval( moveCursorTo.h );
			moveCursorTo.hTo = setTimeout( moveCursorTo.ends, 0 );
		};
	};
	moveCursorTo.ends = function () {
		moveCursorTo.cb && moveCursorTo.cb.call( moveCursorTo.obj );
	};
	moveCursorTo.on = function () {
		moveCursorTo.ent.style.left = moveCursorTo.x0 - 32 + "px";
		moveCursorTo.ent.style.top = moveCursorTo.y0 - 32 + "px";
		moveCursorTo.ent.style.display = "";
	};
	moveCursorTo.off = function () {
		moveCursorTo.ent.style.display = "none";
	};
	moveCursorTo.click = function ( ent, ctrlKey, obj, cb ) {
		moveCursorTo.cb = cb;
		moveCursorTo.obj = obj;
		moveCursorTo.entity = ent;
		moveCursorTo.ent.className = "FBDEditor_demo_clickCursor";
		if ( ctrlKey ) {
			moveCursorTo.cEnt.className = "FBDEditor_demo_cntrlKey";
			moveCursorTo.cEnt.style.left = moveCursorTo.x0 + "px";
			moveCursorTo.cEnt.style.top = moveCursorTo.y0 - 120 + "px";
			moveCursorTo.cEnt.style.display = "";
			moveCursorTo.hTo = setTimeout( moveCursorTo.pressCtrl, 500 );
		} else {
			moveCursorTo.down();
		};
	};
	moveCursorTo.down = function () {
		(moveCursorTo.entity || document).onclick(
			{"pageX":moveCursorTo.x0,
			"pageY":moveCursorTo.y0,
			"ctrlKey":!moveCursorTo.cEnt.style.display,
			"stopPropagation":function(){} }
		);
		moveCursorTo.hTo = setTimeout( moveCursorTo.up, 500 );
	};
	moveCursorTo.pressCtrl = function () {
		moveCursorTo.cEnt.className = "FBDEditor_demo_cntrlKey1";
		moveCursorTo.hTo = setTimeout( moveCursorTo.down, 500 );
	};
	moveCursorTo.up = function () {
		moveCursorTo.ent.className = "FBDEditor_demo_cursor";
		if ( moveCursorTo.cEnt.style.display ) {
			moveCursorTo.hTo = setTimeout( moveCursorTo.unpressCntrl, 500 );
		} else {
			moveCursorTo.unpressCntrl();
		};
	};
	moveCursorTo.halt = function () {
		moveCursorTo.cEnt.style.display = "none";
		moveCursorTo.h && clearInterval( moveCursorTo.h );
		moveCursorTo.hTo && clearTimeout( moveCursorTo.hTo );
	};
	moveCursorTo.unpressCntrl = function () {
		moveCursorTo.cEnt.style.display = "none";
		moveCursorTo.cb && moveCursorTo.cb.call( moveCursorTo.obj );
	};
	( moveCursorTo.ent = document.createElement( "div" ) ).className = "FBDEditor_demo_cursor";
	( moveCursorTo.cEnt = document.createElement( "div" ) ).className = "FBDEditor_demo_cntrlKey";
	document.body.appendChild( moveCursorTo.ent );
	document.body.appendChild( moveCursorTo.cEnt );
	moveCursorTo.ent.style.display = moveCursorTo.cEnt.style.display = "none";
	moveCursorTo.h = null;
	moveCursorTo.xN = 0;
	moveCursorTo.yN = 0;
	moveCursorTo.x0 = 500;
	moveCursorTo.y0 = 300;
	moveCursorTo.i = 0;
	moveCursorTo.delta = null;
	moveCursorTo.deltaX = null;
	moveCursorTo.deltaY = null;
	moveCursorTo.obj = null;
	moveCursorTo.cb = null;

	var writeText = function ( e, txt, obj, cb ) {
		var i = 0;
		e.value = "";
		var h = setInterval(
			function () {
				if ( i < txt.length ) {
					e.value += txt.charAt( i );
				} else if ( i > txt.length + 5 ) {
					clearInterval( h );
					cb && cb.call( obj );	// TODO cb can not call writeText!
				};
				i++;
			},
			300 );
	};

	var getByClass = function ( name ) {
		var a = document.getElementsByTagName( "a" );
		for ( var i = a.length; i--; )
			if ( a[i].className.indexOf( name ) == 0 ) return a[i];
		return null;
	};
	var getByText = function ( text ) {
		var a = document.getElementsByTagName( "a" );
		for ( var i = a.length; i--; )
			if ( a[i].childNodes.length && a[i].childNodes[0].childNodes[0].nodeValue == text ) return a[i];
		return null;
	};
	var getModalButton = function ( n ) {	// 0 -OK; 1 - Cancell;
		return findClass(
				findClass( document.body, "yWin_WinDiv" ).lastChild,
					"yWin_WinContent" ).lastChild.childNodes[n];
	};
	var entityClick = function ( e, lock ) {
		var x = e.offsetWidth >> 1;
		var y = e.offsetHeight >> 1;
		var i = e;
		if ( lock )	lock = findClass( findClass( document.body, "yWin_WinDiv" ), "yWin_LockDiv" );
		do {
			try {
				x += i.offsetLeft;
				y += i.offsetTop;
			} catch ( e ) {};
		} while ( ( i = i.offsetParent ) && i != document.body );
		moveCursorTo(
			x,
			y,
			null,
			function () {
				moveCursorTo.click( e, null, player, player.go );
			},
			lock
		);
	};

	this.init = function () {
		return true;
	};
	var findClass = function ( e, clsName ) {
		for ( var i = 0; i < e.childNodes.length; i++ )
			if ( e.childNodes[i].className == clsName ) return e.childNodes[i];
		return null;
	};
	var clickToButton = function ( cls ) {
		var i;
		if ( cls == "OK" || cls == "CANCEL" ) {
			i = findClass(
					findClass( document.body, "yWin_WinDiv" ).lastChild,
						"yWin_WinContent" ).lastChild.childNodes[cls == "OK" ? 0 : 1];
		} else if ( cls == "CAPTION" ) {
			i = findClass( document.body, "yWin_WinDiv" );
			for ( var j = 0; j < i.childNodes.length; j++ ) {
				if ( i.childNodes[j].className == "yWin_Win" ) {
					var c = findClass( i.childNodes[j], "yWin_WinCaption" );
					if ( c && c.firstChild.nodeValue == arguments[1] ) {
						i = c;
						break;
					};
				};
			};
		} else {
			i = btns[cls];
		};
		var x = i.offsetWidth >> 1;
		var y = i.offsetHeight >> 1;
		var ent = i;
		do {
			x += i.offsetLeft;
			y += i.offsetTop;
		} while ( ( i = i.offsetParent ) && i != document.body );
		moveCursorTo(
			x,
			y,
			null,
			function () {
				moveCursorTo.click( ent, null, player, player.go );
			}
		);
	};

	var player = function ( rec ) {
		player.i = 0;
		player.rec = rec;
		player.go();
	};
	player.i = 10000;
	player.go = function () {
		if ( player.i >= player.rec.length ) {
			player.i = 10000;
			endPlayAction && endPlayAction();
			return;
		};
		var c = player.rec[player.i];
		switch ( c[0] ) {
			case "eClick":
				moveCursorTo.click( document.getElementById(c[1]), false, player, player.go );
				break;
			case "rClick":
			case "click":
				var l;
				if ( c[1] ) {
					l = findClass( findClass( document.body, "yWin_WinDiv" ), "yWin_LockDiv" );
				};
				moveCursorTo.click( c[1] && l, c[0] == "rClick", player, player.go );
				break;
			case "exit?":
				if ( cancelPressed ) {
					player.i = 10000;
					endPlayAction && endPlayAction();
				} else setTimeout( function(){ player.go(); }, 0 );
				break;
			case "goto":
				var l;
				if ( c[3] ) {
					l = findClass( findClass( document.body, "yWin_WinDiv" ), "yWin_LockDiv" );
				};
				moveCursorTo( c[1], c[2], player, player.go, c[3] && l );
				break;
			case 'wait':
				setTimeout( function(){ player.go(); }, c[1] );
				break;
			case 'OK':
				entityClick( getModalButton(0), true );
				break;
			case 'CANCEL':
				clickToButton("CANCEL");
				break;
			case 'CAPTION':
				clickToButton("CAPTION",c[1]);
				break;
			case 'tool':
				entityClick( getByClass( c[1] ) );
				break;
			case 'button':
				entityClick( getByText( c[1] ) );
				break;
			case 'entity':
				entityClick( document.getElementById(c[1]) );
				break;
			case 'loadSample':
				ctxt.controller._loadSample( samples[ c[1] ] );
				setTimeout( function(){ player.go(); }, 0 );
				break;
			case 'moveWin':
				ctxt.controller._moveWinTo(c[1],c[2],c[3]);
				setTimeout( function(){ player.go(); }, 0 );
				break;
			case "text":
				var i;
				switch ( c[1] ) {
					case "g":
						i = document.getElementById("FBDEditor_fbeditInput");
					case "e":
						i = document.getElementById("FBDEditor_promptGinput");
					default:
						var inps = document.getElementsByTagName("input");
						for ( var j = 0; j < inps.length; j++ )
							if ( !( i = inps[j] ).id ) break;
				};
				if ( !i ) throw( new Error( "Error of find input (demo)" ) );
				writeText(i,c[2],player,player.go);
				break;
		};
		player.i++;
	};
	var samples = {
		0:'{"blocks":{},"bd":[]}',
		5:'{"blocks":{'
			+'"engineControl":{"inputs":["level","com","call1","call2","call3","call4","call5","doorIsClose"],"outputs":["up","down","done"]},'
			+'"doorControl":{"inputs":["start","isClose","isOpen"],"outputs":["open","close","done"]},'
			+'"DMUX":{"inputs":["i1","i2","i3","i4","i5"],"outputs":["code",""]}},'
			+'"bd":['
			+'{"tp":"trace", "x0":392, "y0":216, "x1":440, "y1":304, "l0":-1,"label":"demoEditEntity003"},'
			+'{"tp":"trace", "x0":320, "y0":160, "x1":368, "y1":376, "l0":-1},'
			+'{"tp":"input", "x":48, "y":216, "text":"control5"},'
			+'{"tp":"input", "x":48, "y":200, "text":"control4"},'
			+'{"tp":"input", "x":48, "y":184, "text":"control3"},'
			+'{"tp":"input", "x":48, "y":168, "text":"control2"},'
			+'{"tp":"input", "x":48, "y":152, "text":"control1"},'
			+'{"tp":"fb", "x":208, "y":152, "text":"controlDMUX", "classId":"DMUX","label":"demoEditEntity001"},'
			+'{"tp":"input", "x":208, "y":400, "text":"call1"},'
			+'{"tp":"input", "x":208, "y":416, "text":"call2"},'
			+'{"tp":"input", "x":208, "y":432, "text":"call3"},'
			+'{"tp":"input", "x":208, "y":448, "text":"call4"},'
			+'{"tp":"input", "x":208, "y":464, "text":"call5"},'
			+'{"tp":"trace", "x0":320, "y0":408, "x1":368, "y1":408, "l0":-1},'
			+'{"tp":"trace", "x0":320, "y0":424, "x1":368, "y1":424, "l0":-1},'
			+'{"tp":"trace", "x0":320, "y0":440, "x1":368, "y1":440, "l0":-1},'
			+'{"tp":"trace", "x0":320, "y0":456, "x1":368, "y1":456, "l0":-1},'
			+'{"tp":"trace", "x0":320, "y0":472, "x1":368, "y1":472, "l0":-1},'
			+'{"tp":"trace", "x0":288, "y0":520, "x1":368, "y1":488, "l0":32},'
			+'{"tp":"trace", "x0":480, "y0":408, "x1":512, "y1":504, "l0":-1},'
			+'{"tp":"trace", "x0":480, "y0":392, "x1":528, "y1":392, "l0":-1},'
			+'{"tp":"trace", "x0":480, "y0":376, "x1":528, "y1":376, "l0":-1},'
			+'{"tp":"fb", "x":368, "y":368, "text":"conControl", "classId":"engineControl"},'
			+'{"tp":"trace", "x0":624, "y0":520, "x1":672, "y1":520, "l0":-1},'
			+'{"tp":"trace", "x0":624, "y0":504, "x1":672, "y1":504, "l0":-1},'
			+'{"tp":"trace", "x0":288, "y0":536, "x1":512, "y1":536, "l0":-1},'
			+'{"tp":"trace", "x0":288, "y0":520, "x1":512, "y1":520, "l0":-1},'
			+'{"tp":"fb", "x":512, "y":496, "text":"door", "classId":"doorControl"},'
			+'{"tp":"output", "x":672, "y":512, "text":"closeDoor"},'
			+'{"tp":"output", "x":672, "y":496, "text":"openDoor"},'
			+'{"tp":"output", "x":528, "y":384, "text":"engineDown"},'
			+'{"tp":"output", "x":528, "y":368, "text":"engineUp"},'
			+'{"tp":"input", "x":176, "y":512, "text":"doorIsClose"},'
			+'{"tp":"input", "x":176, "y":528, "text":"doorIsOpen"},'
			+'{"tp":"trace", "x0":160, "y0":368, "x1":208, "y1":368, "l0":-1},'
			+'{"tp":"trace", "x0":160, "y0":352, "x1":208, "y1":352, "l0":-1},'
			+'{"tp":"trace", "x0":160, "y0":336, "x1":208, "y1":336, "l0":-1},'
			+'{"tp":"trace", "x0":160, "y0":320, "x1":208, "y1":320, "l0":-1},'
			+'{"tp":"trace", "x0":160, "y0":304, "x1":208, "y1":304, "l0":-1},'
			+'{"tp":"fb", "x":208, "y":296, "text":"controlDMUX", "classId":"DMUX"},'
			+'{"tp":"input", "x":48, "y":360, "text":"control5"},'
			+'{"tp":"input", "x":48, "y":344, "text":"control4"},'
			+'{"tp":"input", "x":48, "y":328, "text":"control3"},'
			+'{"tp":"input", "x":48, "y":312, "text":"control2"},'
			+'{"tp":"input", "x":48, "y":296, "text":"control1"},'
			+'{"tp":"trace", "x0":160, "y0":224, "x1":208, "y1":224, "l0":-1},'
			+'{"tp":"trace", "x0":160, "y0":208, "x1":208, "y1":208, "l0":-1},'
			+'{"tp":"trace", "x0":160, "y0":192, "x1":208, "y1":192, "l0":-1},'
			+'{"tp":"trace", "x0":160, "y0":176, "x1":208, "y1":176, "l0":-1},'
			+'{"tp":"trace", "x0":160, "y0":160, "x1":192, "y1":160, "l0":-1,"label":"demoEditEntity002"}'
			+']'
			+'}',
		7:'{"blocks":{'
			+'"engineControl":{"inputs":["level","com","call1","call2","call3","call4","call5","doorIsClose"],"outputs":["up","down","done"]},'
			+'"doorControl":{"inputs":["start","isClose","isOpen"],"outputs":["open","close","done"]},'
			+'"DMUX":{"inputs":["i1","i2","i3","i4","i5"],"outputs":["code",""]}},'
			+'"bd":['
			+'{"tp":"input", "x":208, "y":400, "text":"call1"},'
			+'{"tp":"input", "x":208, "y":416, "text":"call2"},'
			+'{"tp":"input", "x":208, "y":432, "text":"call3"},'
			+'{"tp":"input", "x":208, "y":448, "text":"call4"},'
			+'{"tp":"input", "x":208, "y":464, "text":"call5"},'
			+'{"tp":"trace", "x0":320, "y0":408, "x1":368, "y1":408, "l0":-1},'
			+'{"tp":"trace", "x0":320, "y0":424, "x1":368, "y1":424, "l0":-1},'
			+'{"tp":"trace", "x0":320, "y0":440, "x1":368, "y1":440, "l0":-1},'
			+'{"tp":"trace", "x0":320, "y0":456, "x1":368, "y1":456, "l0":-1},'
			+'{"tp":"trace", "x0":320, "y0":472, "x1":368, "y1":472, "l0":-1},'
			+'{"tp":"trace", "x0":288, "y0":520, "x1":368, "y1":488, "l0":32},'
			+'{"tp":"trace", "x0":480, "y0":408, "x1":512, "y1":504, "l0":-1},'
			+'{"tp":"trace", "x0":480, "y0":392, "x1":528, "y1":392, "l0":-1},'
			+'{"tp":"trace", "x0":480, "y0":376, "x1":528, "y1":376, "l0":-1},'
			+'{"tp":"trace", "x0":320, "y0":304, "x1":368, "y1":392, "l0":16},'
			+'{"tp":"trace", "x0":320, "y0":160, "x1":368, "y1":376, "l0":32},'
			+'{"tp":"fb", "x":368, "y":368, "text":"conControl", "classId":"engineControl"},'
			+'{"tp":"trace", "x0":624, "y0":520, "x1":672, "y1":520, "l0":-1},'
			+'{"tp":"trace", "x0":624, "y0":504, "x1":672, "y1":504, "l0":-1},'
			+'{"tp":"trace", "x0":288, "y0":536, "x1":512, "y1":536, "l0":-1},'
			+'{"tp":"trace", "x0":288, "y0":520, "x1":512, "y1":520, "l0":-1},'
			+'{"tp":"fb", "x":512, "y":496, "text":"door", "classId":"doorControl"},'
			+'{"tp":"output", "x":672, "y":512, "text":"closeDoor"},'
			+'{"tp":"output", "x":672, "y":496, "text":"openDoor"},'
			+'{"tp":"output", "x":528, "y":384, "text":"engineDown"},'
			+'{"tp":"output", "x":528, "y":368, "text":"engineUp"},'
			+'{"tp":"input", "x":176, "y":512, "text":"doorIsClose"},'
			+'{"tp":"input", "x":176, "y":528, "text":"doorIsOpen"},'
			+'{"tp":"trace", "x0":160, "y0":368, "x1":208, "y1":368, "l0":-1},'
			+'{"tp":"trace", "x0":160, "y0":352, "x1":208, "y1":352, "l0":-1},'
			+'{"tp":"trace", "x0":160, "y0":336, "x1":208, "y1":336, "l0":-1},'
			+'{"tp":"trace", "x0":160, "y0":320, "x1":208, "y1":320, "l0":-1},'
			+'{"tp":"trace", "x0":160, "y0":304, "x1":208, "y1":304, "l0":-1},'
			+'{"tp":"fb", "x":208, "y":296, "text":"controlDMUX", "classId":"DMUX"},'
			+'{"tp":"input", "x":48, "y":360, "text":"control5"},'
			+'{"tp":"input", "x":48, "y":344, "text":"control4"},'
			+'{"tp":"input", "x":48, "y":328, "text":"control3"},'
			+'{"tp":"input", "x":48, "y":312, "text":"control2"},'
			+'{"tp":"input", "x":48, "y":296, "text":"control1"},'
			+'{"tp":"trace", "x0":160, "y0":224, "x1":208, "y1":224, "l0":-1},'
			+'{"tp":"trace", "x0":160, "y0":208, "x1":208, "y1":208, "l0":-1},'
			+'{"tp":"trace", "x0":160, "y0":192, "x1":208, "y1":192, "l0":-1},'
			+'{"tp":"trace", "x0":160, "y0":176, "x1":208, "y1":176, "l0":-1,"label":"demoDelEntity003"},'
			+'{"tp":"trace", "x0":160, "y0":160, "x1":208, "y1":160, "l0":-1,"label":"demoDelEntity004"},'
			+'{"tp":"fb", "x":208, "y":152, "text":"levelDMUX", "classId":"DMUX"},'
			+'{"tp":"input", "x":48, "y":216, "text":"level5"},'
			+'{"tp":"input", "x":48, "y":200, "text":"level4"},'
			+'{"tp":"input", "x":48, "y":184, "text":"level3"},'
			+'{"tp":"input", "x":48, "y":168, "text":"level2","label":"demoDelEntity002"},'
			+'{"tp":"input", "x":48, "y":152, "text":"level1","label":"demoDelEntity001"}'
			+']'
			+'}',
		8:'{"blocks":{'
			+'"engineControl":{"inputs":["level","com","call1","call2","call3","call4","call5","doorIsClose"],"outputs":["up","down","done"]},'
			+'"doorControl":{"inputs":["start","isClose","isOpen"],"outputs":["open","close","done"]},'
			+'"DMUX":{"inputs":["i1","i2","i3","i4","i5"],"outputs":["code",""]}},'
			+'"bd":['
			+'{"tp":"input", "x":208, "y":400, "text":"call1"},'
			+'{"tp":"input", "x":208, "y":416, "text":"call2"},'
			+'{"tp":"input", "x":208, "y":432, "text":"call3"},'
			+'{"tp":"input", "x":208, "y":448, "text":"call4"},'
			+'{"tp":"input", "x":208, "y":464, "text":"call5"},'
			+'{"tp":"trace", "x0":320, "y0":408, "x1":368, "y1":408, "l0":-1},'
			+'{"tp":"trace", "x0":320, "y0":424, "x1":368, "y1":424, "l0":-1},'
			+'{"tp":"trace", "x0":320, "y0":440, "x1":368, "y1":440, "l0":-1},'
			+'{"tp":"trace", "x0":320, "y0":456, "x1":368, "y1":456, "l0":-1},'
			+'{"tp":"trace", "x0":320, "y0":472, "x1":368, "y1":472, "l0":-1},'
			+'{"tp":"trace", "x0":288, "y0":520, "x1":368, "y1":488, "l0":32},'
			+'{"tp":"trace", "x0":480, "y0":408, "x1":512, "y1":504, "l0":-1},'
			+'{"tp":"trace", "x0":480, "y0":392, "x1":528, "y1":392, "l0":-1},'
			+'{"tp":"trace", "x0":480, "y0":376, "x1":528, "y1":376, "l0":-1},'
			+'{"tp":"trace", "x0":320, "y0":304, "x1":368, "y1":392, "l0":16},'
			+'{"tp":"trace", "x0":320, "y0":160, "x1":368, "y1":376, "l0":32},'
			+'{"tp":"fb", "x":368, "y":368, "text":"conControl", "classId":"engineControl"},'
			+'{"tp":"trace", "x0":624, "y0":470, "x1":672, "y1":470, "l0":-1},'	//
			+'{"tp":"trace", "x0":624, "y0":454, "x1":672, "y1":454, "l0":-1},'	//
			+'{"tp":"trace", "x0":288, "y0":536, "x1":512, "y1":536, "l0":-1},'
			+'{"tp":"trace", "x0":288, "y0":520, "x1":512, "y1":520, "l0":-1},'
			+'{"tp":"fb", "x":512, "y":446, "text":"door", "classId":"doorControl"},'	//496
			+'{"tp":"output", "x":672, "y":462, "text":"closeDoor"},'	//512
			+'{"tp":"output", "x":672, "y":446, "text":"openDoor"},'	//496
			+'{"tp":"output", "x":528, "y":384, "text":"engineDown"},'
			+'{"tp":"output", "x":528, "y":368, "text":"engineUp"},'
			+'{"tp":"input", "x":72, "y":414, "text":"doorIsClose","label":"demoMoveEntity001"},'	//"x":176, "y":512,
			+'{"tp":"input", "x":72, "y":430, "text":"doorIsOpen","label":"demoMoveEntity002"},'	//"x":176, "y":528,
			+'{"tp":"trace", "x0":160, "y0":368, "x1":208, "y1":368, "l0":-1},'
			+'{"tp":"trace", "x0":160, "y0":352, "x1":208, "y1":352, "l0":-1},'
			+'{"tp":"trace", "x0":160, "y0":336, "x1":208, "y1":336, "l0":-1},'
			+'{"tp":"trace", "x0":160, "y0":320, "x1":208, "y1":320, "l0":-1},'
			+'{"tp":"trace", "x0":160, "y0":304, "x1":208, "y1":304, "l0":-1},'
			+'{"tp":"fb", "x":208, "y":296, "text":"controlDMUX", "classId":"DMUX"},'
			+'{"tp":"input", "x":48, "y":360, "text":"control5"},'
			+'{"tp":"input", "x":48, "y":344, "text":"control4"},'
			+'{"tp":"input", "x":48, "y":328, "text":"control3"},'
			+'{"tp":"input", "x":48, "y":312, "text":"control2"},'
			+'{"tp":"input", "x":48, "y":296, "text":"control1"},'
			+'{"tp":"trace", "x0":160, "y0":224, "x1":208, "y1":224, "l0":-1},'
			+'{"tp":"trace", "x0":160, "y0":208, "x1":208, "y1":208, "l0":-1},'
			+'{"tp":"trace", "x0":160, "y0":192, "x1":208, "y1":192, "l0":-1},'
			+'{"tp":"trace", "x0":160, "y0":176, "x1":208, "y1":176, "l0":-1},'
			+'{"tp":"trace", "x0":160, "y0":160, "x1":208, "y1":160, "l0":-1},'
			+'{"tp":"fb", "x":208, "y":152, "text":"levelDMUX", "classId":"DMUX"},'
			+'{"tp":"input", "x":48, "y":216, "text":"level5"},'
			+'{"tp":"input", "x":48, "y":200, "text":"level4"},'
			+'{"tp":"input", "x":48, "y":184, "text":"level3"},'
			+'{"tp":"input", "x":48, "y":168, "text":"level2"},'
			+'{"tp":"input", "x":48, "y":152, "text":"level1"}'
			+']'
			+'}',
		9:'{"blocks":{'
			+'"engineControl":{"inputs":["level","com","call1","call2","call3","call4","call5","doorIsClose"],"outputs":["up","down","done"]},'
			+'"doorControl":{"inputs":["start","isClose","isOpen"],"outputs":["open","close","done"]},'
			+'"DMUX":{"inputs":["i1","i2","i3","i4","i5"],"outputs":["code",""]}},'
			+'"bd":['
			+'{"tp":"input", "x":208, "y":400, "text":"call1"},'
			+'{"tp":"input", "x":208, "y":416, "text":"call2"},'
			+'{"tp":"input", "x":208, "y":432, "text":"call3"},'
			+'{"tp":"input", "x":208, "y":448, "text":"call4"},'
			+'{"tp":"input", "x":208, "y":464, "text":"call5"},'
			+'{"tp":"trace", "x0":320, "y0":408, "x1":368, "y1":408, "l0":-1},'
			+'{"tp":"trace", "x0":320, "y0":424, "x1":368, "y1":424, "l0":-1},'
			+'{"tp":"trace", "x0":320, "y0":440, "x1":368, "y1":440, "l0":-1},'
			+'{"tp":"trace", "x0":320, "y0":456, "x1":368, "y1":456, "l0":-1},'
			+'{"tp":"trace", "x0":320, "y0":472, "x1":368, "y1":472, "l0":-1},'
			+'{"tp":"trace", "x0":288, "y0":520, "x1":368, "y1":488, "l0":32},'
			+'{"tp":"trace", "x0":480, "y0":408, "x1":512, "y1":504, "l0":-1},'
			+'{"tp":"trace", "x0":480, "y0":392, "x1":528, "y1":392, "l0":-1},'
			+'{"tp":"trace", "x0":480, "y0":376, "x1":528, "y1":376, "l0":-1},'
			+'{"tp":"trace", "x0":320, "y0":304, "x1":368, "y1":392, "l0":16},'
			+'{"tp":"trace", "x0":320, "y0":160, "x1":368, "y1":376, "l0":32},'
			+'{"tp":"fb", "x":368, "y":368, "text":"conControl", "classId":"engineControl"},'
			+'{"tp":"trace", "x0":624, "y0":518, "x1":672, "y1":518, "l0":-1},'
			+'{"tp":"trace", "x0":624, "y0":502, "x1":672, "y1":502, "l0":-1},'
			+'{"tp":"trace", "x0":288, "y0":520, "x1":512, "y1":520, "l0":-1,"label":"demoCopyEntity002"},'
			+'{"tp":"fb", "x":512, "y":494, "text":"door", "classId":"doorControl"},'
			+'{"tp":"output", "x":672, "y":510, "text":"closeDoor"},'
			+'{"tp":"output", "x":672, "y":494, "text":"openDoor"},'
			+'{"tp":"output", "x":528, "y":384, "text":"engineDown"},'
			+'{"tp":"output", "x":528, "y":368, "text":"engineUp"},'
			+'{"tp":"input", "x":176, "y":510, "text":"doorIsClose","label":"demoCopyEntity001"},'
			+'{"tp":"trace", "x0":160, "y0":368, "x1":208, "y1":368, "l0":-1},'
			+'{"tp":"trace", "x0":160, "y0":352, "x1":208, "y1":352, "l0":-1},'
			+'{"tp":"trace", "x0":160, "y0":336, "x1":208, "y1":336, "l0":-1},'
			+'{"tp":"trace", "x0":160, "y0":320, "x1":208, "y1":320, "l0":-1},'
			+'{"tp":"trace", "x0":160, "y0":304, "x1":208, "y1":304, "l0":-1},'
			+'{"tp":"fb", "x":208, "y":296, "text":"controlDMUX", "classId":"DMUX"},'
			+'{"tp":"input", "x":48, "y":360, "text":"control5"},'
			+'{"tp":"input", "x":48, "y":344, "text":"control4"},'
			+'{"tp":"input", "x":48, "y":328, "text":"control3"},'
			+'{"tp":"input", "x":48, "y":312, "text":"control2"},'
			+'{"tp":"input", "x":48, "y":296, "text":"control1"}'
			+']'
			+'}'
};
};